package com.example.libraryManager.controller;


import com.example.libraryManager.entity.Books;
import com.example.libraryManager.entity.Borrow;
import com.example.libraryManager.service.impl.BorrowService;
import com.example.libraryManager.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-09-02
 */
@RestController
@RequestMapping("/borrow")
public class BorrowController {

    @Autowired
    BorrowService borrowService;

    /**
     * 保存 借阅书籍
     * @param borrow 借阅书籍 对象
     * @return
     */
    @GetMapping("/saveBorrow")
    public ResultVo saveBorrow(Borrow borrow){
        ResultVo resultVo=borrowService.saveAndCheck(borrow);
        return resultVo;
    }

    /**
     *  收藏 查询全部
     * @param user
     * @return
     */
    @GetMapping("/pageList/{user}")
    public ResultVo pageList(
            @PathVariable("user") Integer user
    ){
        ResultVo resultVo = borrowService.pageList(user);

        return resultVo;
    }

    /**
     * 收藏 删除
     * @param books
     * @return
     */
    @GetMapping("/deleteBorrow")
    public ResultVo deleteBorrow(Books books){
        ResultVo resultVo=borrowService.deleteByBookId(books);
        return resultVo;
    }

}

